module.exports = function(grunt){
	grunt.initConfig({
        pkg : grunt.file.readJSON('package.json'),
		concat : {
			'<%= pkg.name %>/src/concat/js/lib.js':'<%= pkg.name %>/src/js/common/*.js',
			'<%= pkg.name %>/src/concat/js/all.js':['<%= pkg.name %>/src/js/shareTools.js','<%= pkg.name %>/src/js/index.js','<%= pkg.name %>/src/js/Main.js'],
			'<%= pkg.name %>/src/concat/css/all.css' : ['<%= pkg.name %>/src/css/normalize.css','<%= pkg.name %>/src/css/style.css']
		},
        uglify : {
			options: {
				banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
			},

			/*build: {
				src: [
					'<%= pkg.name %>/dist/js/all.js',
				],
				dest:'<%= pkg.name %>/dist/js/all.min.js'
			}*/

            target : {
                files : {
					/*基础库*/
					'<%= pkg.name %>/dist/js/lib.min.js': '<%= pkg.name %>/src/concat/js/lib.js',
					'<%= pkg.name %>/dist/js/all.min.js': '<%= pkg.name %>/src/concat/js/all.js',

					/*分步加载*/
					'<%= pkg.name %>/dist/js/Plain.js': '<%= pkg.name %>/src/js/Plain.js',
					'<%= pkg.name %>/dist/js/Player.js': '<%= pkg.name %>/src/js/Player.js',
					'<%= pkg.name %>/dist/js/Enemy.js': '<%= pkg.name %>/src/js/Enemy.js',
					'<%= pkg.name %>/dist/js/Weiba.js': '<%= pkg.name %>/src/js/Weiba.js',
					'<%= pkg.name %>/dist/js/utils.js': '<%= pkg.name %>/src/js/utils.js'
                }
            }
        },
		cssmin : {
            target : {
                files : {
                    '<%= pkg.name %>/dist/css/all.min.css': '<%= pkg.name %>/src/concat/css/all.css'
                }
            }
        },

		/*开发版*/
		'template':{
			'process-html-template':{
				'options': {
					'data': {
						'resource':"."
					}
				},
				'files': {
					'<%= pkg.name %>/src/index.html': ['<%= pkg.name %>/tpl/index.html'],
					'<%= pkg.name %>/src/landspace.html': ['<%= pkg.name %>/tpl/landspace.html']
				}
			}
		},

		/*发布版*/
		'template':{
			'process-html-template':{
				'options': {
					'data': {
						'resource':".",
						'allcss':"all.min.css",
						"libjs":"lib.min.js",
						"alljs":"all.min.js"
					}
				},
				'files': {
					'<%= pkg.name %>/dist/index.html': ['<%= pkg.name %>/tpl/prod_index.html'],
					'<%= pkg.name %>/dist/landspace.html': ['<%= pkg.name %>/tpl/prod_landspace.html']
				}
			}
		},

		htmlmin: {
			dist:{
				options: {
					removeComments: true,
					collapseWhitespace: true,
					removeEmptyAttributes: true,
					removeCommentsFromCDATA:true,
					removeRedundantAttributes: true,
					collapseBooleanAttributes:true
				},
				files: {
					'<%= pkg.name %>/dist/index.html': '<%= pkg.name %>/dist/index.html',
					'<%= pkg.name %>/dist/landspace.html': '<%= pkg.name %>/dist/landspace.html'
				}
			}
		},

        copy : {
            target : {
                files : [
					/*依赖库文件*/
					{expand: true,cwd: '<%= pkg.bowerPath %>/zepto',src: ['zepto.min.js'],dest: '<%= pkg.name %>/src/js/common'},
					/*基本文件*/
					{expand: true,cwd: '<%= pkg.name %>/src/images/',src: ['*.*'],dest: '<%= pkg.name %>/dist/images/'},
					{expand: true,cwd: '<%= pkg.name %>/src/sound/',src: ['*.*'],dest: '<%= pkg.name %>/dist/sound/'},
                ]
            }
        }

	});
  	grunt.loadNpmTasks('grunt-contrib-concat');
  	grunt.loadNpmTasks('grunt-template');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-cssmin');
    grunt.loadNpmTasks('grunt-contrib-copy');
    grunt.loadNpmTasks('grunt-template');
	grunt.loadNpmTasks('grunt-contrib-htmlmin');
	grunt.registerTask('default', ['template','copy']);
	grunt.registerTask('dist', ['template','copy','concat','uglify','cssmin','htmlmin']);
}